package com.hockeo.client.ui.menu;

import com.extjs.gxt.ui.client.widget.menu.MenuItem;
import com.hockeo.client.VHMain;
import com.hockeo.client.ui.base.VHEditorGrid;
import com.hockeo.client.ui.base.VHGridContextMenu;

/**
 * Context menu for the various data editors.
 *
 * @version $Id$
 * @author jjanke
 */
public class GridDataEditorContextMenu extends VHGridContextMenu
{
  private final VHEditorGrid d_editorGrid;
  private final MenuItem d_miEdit;
  private final MenuItem d_miDelete;

  public GridDataEditorContextMenu( VHEditorGrid grid )
  {
    super( grid.getLowLevelGrid() );

    d_editorGrid = grid;

    d_miEdit = new MenuItem( VHMain.getAppConstants().actionEdit(), VHMain.ICON_EDIT, getDefaultSelectionListener() );
    add( d_miEdit );

    d_miDelete = new MenuItem( VHMain.getAppConstants().actionDelete(), VHMain.ICON_DELETE, getDefaultSelectionListener() );
    add( d_miDelete );
  }

  @Override
  protected void menuItemSelected( final MenuItem miClicked )
  {
    if ( miClicked.equals( d_miEdit ) )
      d_editorGrid.editLine( getModelLastClicked() );
    else if ( miClicked.equals( d_miDelete ) )
      d_editorGrid.deleteLine( getModelLastClicked() );
    else
      super.menuItemSelected( miClicked );
  }
}
